x = int(input())
y = 0
if len(str(x)) == 4:
    for i in range(2, x + 1):
        if str(i) in str(x):
            a = False
            for n in range(2, i // 2 + 1):
                if i % n == 0:
                    a = True
                    break
            if a:
                continue
            else:
                max_dl = max(y, i)
print(y)
